package com.googlecode.cswish.struts.conversion;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.components.TextArea;

import com.googlecode.cswish.model.PageElement;
import com.googlecode.cswish.model.PropertyInfo;

/**
 * Convert textarea object
 * 	 
 * @author jerry.feng Date: 2009-1-13
 */
public class TextAreaElementConverter extends CommonElementConverter {
	
	@Override
	public PageElement convert(ConversionContext context) {
		PropertyInfo propertyInfo = context.getPropertyInfo();
		
		if (propertyInfo.getLength() >= 100) {
			PageElement element = super.convert(context);
			
			Map<String, String> extraParams = new HashMap<String, String>(3);
			extraParams.put("cols", "50");
			extraParams.put("rows", String.valueOf((int)(propertyInfo.getLength() / 50)));
			if (propertyInfo.getLength() >= 500) {
				element.setTheme("ajax");
			}
			element.setType(TextArea.class.getName());
			return element;
		}
		return null;
	}
}